import {useMemo, useState} from "react";
import Child from "./Child.jsx";

export default function MemoDemo() {

    const [count, setCount] = useState(0)
    const [name, setName] = useState('data')

    const add = () => {
        let num = count
        setCount(num + 1)
    }

    //类似computed
    const data = useMemo(() => {
        return name
    }, [name])

    return (
        <div>
            <button onClick={() => add()}>ADD</button>
            <div>{count}</div>
            <Child data={data}></Child>
        </div>
    )
}